/**
 * Created by cxj on 2016/2/22.
 */
var grid;
var bootbox_global;

var grid_show;

//显示签到信息
function showcheckin(objid,datarow) {

    bootbox = bootbox_global;

    var obj = grid.date_list[datarow];


    //alert(objid);


    // intervalid = setInterval(setTimeOutController,0.5);

    // grid_show = new Grid("/workerCheckin/getListPaging", $("#table_my_toast1"), $("#paging_my_toast1"), 1, 10, columns, "worker_id="+objid, 20);

    //初始化
    //grid_show.Init();

    // bootbox_global.dialog({
    //    message: "<table class=\"table_list\" id=\"table_my_toast1\"></table> <div class=\"page_control\" id=\"paging_my_toast1\"><ul></ul>",
    // });

    //bootbox_global.dialog({
    //    message: "<iframe src='/worker/workerlist' style='width: 100%;min-height: 400px;'></iframe>",
    //});
    //return;


    //发送请求
    send_request_direct("/workerCheckin/getListPaging", "worker_id="+objid, function process_data(data) {


        //  alert(data.data.data.length);

        var columns = [
            {title : '编号',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

                return "<span>"+(parseInt(datarow)+1)+"</span>";
            }},
            { title: '签到时间', dataIndex: 'create_time',},
            { title: '操作人', dataIndex: 'created_by',},


        ];

        var message = getGridInfo(data.data.data,columns);

        bootbox_content_alert(message);


    }, function process_fail(data) {

        //操作失败
        AlertError(bootbox, data.msg);


    });

}



//查看对象
function viewObj(objid,datarow) {


    show_div_grid();

    var obj = grid.date_list[datarow];

    var columns = [
        {title : '编号',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

            return "<span>"+parseInt( (gridobj.current_page-1)*gridobj.page_rows+parseInt(datarow)+1)+"</span>";
        }},
        { title: '提交时间', dataIndex: 'create_time',},
        {
            title: '状态', dataIndex: 'type', dataSource: function (data, datarow, gridobj, current_column) {

            var type = data[datarow].type;

            return getBankCashName(type);



        }
        },
        { title: '金额', dataIndex: 'amount',},
        { title: '总额(当时余额)', dataIndex: 'balance',},
        { title: '提现中(当时余额)', dataIndex: 'balance_withdrawing',},
        { title: '可用余额(当时余额)', dataIndex: 'balacan_cash',},
        //{ title: '原因', dataIndex: 'reason',},
        //{ title: '操作人', dataIndex: 'created_by',},


    ];

    grid_show = new Grid("/workAmount/getBankCashList", $("#table_my_toast1"), $("#paging_my_toast1"), 1, 10, columns, "&worker_id="+obj.worker_id, 10);

    //初始化
    grid_show.Init();



    return;



}

define([
    "jquery",
    "IO",
    "bootbox"
], function($,IO,bootbox) {

    bootbox_global = bootbox;
    $(function () {

        //每列数据列性
        var columns = [
            {title : '编号',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

                return "<span>"+parseInt( (gridobj.current_page-1)*gridobj.page_rows+parseInt(datarow)+1)+"</span>";
            }},
            { title: '用户id', dataIndex: 'worker_id',},
            { title: '手机号', dataIndex: 'mobile',},
            {title : '认证状态',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

                var is_verify = data[datarow].is_verify;

                if(is_verify == 0)
                    return "<span class='label-default'>未提交</span>";
                if(is_verify == 1)
                    return "<span onclick=\"bootbox_content_alert('"+data[datarow].reason+"')\" class='label-success'>认证成功<span class='glyphicon glyphicon-info-sign' aria-hidden='true'></span></span>";
                if(is_verify == 2)
                    return "<span class='label-info'>认证中</span>";
                if(is_verify == 3)
                    return "<span  onclick=\"bootbox_content_alert('"+data[datarow].reason+"')\" class='label-danger'>认证失败<span class='glyphicon glyphicon-info-sign' aria-hidden='true'></span></span>";


            }},
            { title: '姓名', dataIndex: 'real_name',},
            { title: '头像', dataIndex: 'avatar',dataSource:function(data,datarow,gridobj,current_column) {

                var avatar = data[datarow].avatar;

                if(avatar.length == 0)
                    return "";
                else
                    return "<img class='girdimg img-thumbnail' onclick=\"viewUrl('"+avatar+"')\" src='"+avatar+"'/>"


            }},


            { title: '工种', dataIndex: 'type_name',},
            { title: '身份证', dataIndex: 'idcard',},
            { title: '总资产', dataIndex: 'balance',},
            { title: '提现中', dataIndex: 'balance_withdrawing',},

            {title : '操作',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

                var is_verify = data[datarow].status;


                var  html = "";


                html =  html+"<div class='div_btn'><button onclick=\"viewObj("+data[datarow].request_id+","+datarow+")\" class='btn btn-info'>查看流水日志</button>";

                html = html+"</div>"

                return html;
            }},





        ];


        //数组初始化

        function dataInit() {
            grid = new Grid("/worker/getworkerlist", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 20);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {

            var param="mobile="+$("#mobile").val()+"&real_name="+$("#real_name").val()+"&idcard="+$("#idcard").val()+"&worker_num="+$("#worker_num").val();

            return param;

        }
        dataInit();
        //查询
        $("#query").bind("click", function () {
            dataInit();
        });
    });


});